package com.spider.silence.utils;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;

/**
 * Created by 夏茂轩 on 2017/1/3.
 * @description XML工具类
 */
public class XmlUtil {
    private static XmlUtil ourInstance = new XmlUtil();
    private static SAXReader saxReader=new SAXReader();

    public static XmlUtil getInstance() {
        return ourInstance;
    }

    private XmlUtil() {
    }

    /**
     * @author 夏茂轩
     * @date 2017/1/15 22:34
     * @description 同步方法,读取配置文件,eg:META-INF/QZone-conf.xml
     * @param fileName 配置文件路径
     * @return org.dom4j.Document
     */
    public static synchronized Document getConf(String fileName){
        Document document =null;
        try {
            document = saxReader.read(ourInstance.getClass().getResourceAsStream("/" + fileName));
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return document;
    }
}
